Skip to content

✨ feat: Smooth WRR for Load Balancing#49

Open
zzzhouuu wants to merge 2 commits intoLMRouter:stagingfrom
zzzhouuu:feature/multi-api-key
Open

✨ feat: Smooth WRR for Load Balancing#49
zzzhouuu wants to merge 2 commits intoLMRouter:stagingfrom
zzzhouuu:feature/multi-api-key

Conversation

@zzzhouuu
Copy link
Copy Markdown

@zzzhouuu zzzhouuu commented Oct 5, 2025

The current implementation routes all traffic to the first-configured provider when a model has multiple providers; without changing existing logic, introduce the Smooth WRR algorithm to achieve traffic balance among model providers.

Support adding multiple API keys for a single provider and distribute traffic according to their weights.

config example:

providers:
  groq1:
    type: openai
    base_url: https://api.groq.com/openai/v1
    api_key: sk-groq-api-key
  groq2:
    type: openai
    base_url: https://api.groq.com/openai/v1
    keys:
      - api_key: sk-groq-api-key-1
         weight: 1
      - api_key: sk-groq-api-key-2
         weight: 1
 models:
   kimi-k2-instruct-0905:
    providers:
      - provider: groq1
        model: moonshotai/kimi-k2-instruct-0905
        weight: 1
      - provider: groq2
        model: moonshotai/kimi-k2-instruct-0905
        weight: 1

Use the Smooth WRR algorithm to achieve load balancing for providers and API keys.
@yvbbrjdr
Copy link
Copy Markdown
Contributor

yvbbrjdr commented Oct 5, 2025

Thanks for your contributions! This is indeed very useful feature. I'll review it and merge soon.

@yvbbrjdr
Copy link
Copy Markdown
Contributor

I'd actually like to make the api_key field in the provider accept both a string and a list of objects (key/weight pair), that way the config is cleaner.

@zzzhouuu
Copy link
Copy Markdown
Author

Mainly for compatibility and to allow users who don’t need load balancing to configure simply, the API key is now used to store the key with the highest weight for the current provider, making it easier for the underlying code to call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants